<?php
/**
 * Created by PhpStorm.
 * Author:王晓云
 * Date: 2017/12/24 0024
 * Time: 10:13
 */

namespace app\admin\controller;
use think\Db;
use think\Controller;
class Login extends Controller
{
   public function login(){
       if(request()->isPost()){
           $user=input("post.user");
           $pwd=md5(input("post.password"));
           //die();
           if($res=Db::name("admin")->where("user",$user)->where("pwd",$pwd)->find()){
               session("admin",$res['user']);
               $ip=request()->ip();
               //dump($ip);
               //die();
               Db::name("admin_log")->data(["user"=>$user,"create_time"=>date("Y-m-d H:i:s"),"ip"=>$ip,"content"=>"管理员成功登录"])->insert();
               $this->success("登录成功！","News/newsList");
           }else{
               $this->error("用户名或密码错误");
           }
       }
       return $this->fetch();
   }
   public function loginOut(){
       session("admin",null);
       return $this->redirect("Login/login");

   }
}